﻿<Window x:Class="MainWindow" Loaded="Window_Loaded" Name="w1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Progetto Sicurezza - CA Client" Height="500" Width="820">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Button DockPanel.Dock="Right" Content="CA Certificate Details" Width="130" HorizontalAlignment="Right" Margin="0 5 10 0" Name="buttonMyCert" Visibility="Hidden" Click="buttonMyCert_Click"/>
        <StackPanel>
            <TextBlock Text="Progetto Sicurezza - CA Administration Backend" Margin="5" FontWeight="Bold" FontSize="18" HorizontalAlignment="Center"/>
        </StackPanel>

        <TabControl Name="tabMain" Visibility="Collapsed" Grid.Row="1">
            <TabItem Name="tabRequests" Header="Requests"/>
            <TabItem Name="tabCertificates" Header="Certificates"/>
            <TabItem Name="tabOptions" Header="Options">
                <GroupBox Margin="5" Header="Options">
                    <StackPanel>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>

                            <TextBlock Text="Certificates lifetime: " Margin="3" Grid.Row="0" Grid.Column="0"/>
                            <ComboBox Name="comboCertLife"  Margin="3" Grid.Row="0" Grid.Column="1" SelectedIndex="5" SelectionChanged="ComboLife_SelectionChanged">
                                <ComboBoxItem Tag="30">30 seconds</ComboBoxItem>
                                <ComboBoxItem Tag="60">1 minute</ComboBoxItem>
                                <ComboBoxItem Tag="300">5 minutes</ComboBoxItem>
                                <ComboBoxItem Tag="3600">1 hour</ComboBoxItem>
                                <ComboBoxItem Tag="86400">24 hours</ComboBoxItem>
                                <ComboBoxItem Tag="2592000">30 days</ComboBoxItem>
                                <ComboBoxItem Tag="7776000">90 days</ComboBoxItem>
                                <ComboBoxItem Tag="31536000">1 year</ComboBoxItem>
                            </ComboBox>
                            <TextBlock Text="CRL lifetime: " Margin="3" Grid.Row="1" Grid.Column="0"/>
                            <ComboBox Name="comboCRLLife"  Margin="3" Grid.Row="1" Grid.Column="1" SelectedIndex="3" SelectionChanged="ComboLife_SelectionChanged">
                                <ComboBoxItem Tag="30">30 seconds</ComboBoxItem>
                                <ComboBoxItem Tag="60">1 minute</ComboBoxItem>
                                <ComboBoxItem Tag="300">5 minutes</ComboBoxItem>
                                <ComboBoxItem Tag="3600">1 hour</ComboBoxItem>
                                <ComboBoxItem Tag="86400">24 hours</ComboBoxItem>
                                <ComboBoxItem Tag="2592000">30 days</ComboBoxItem>
                                <ComboBoxItem Tag="7776000">90 days</ComboBoxItem>
                                <ComboBoxItem Tag="31536000">1 year</ComboBoxItem>
                            </ComboBox>
                        </Grid>
                    </StackPanel>
                </GroupBox>
            </TabItem>
        </TabControl>

        <StackPanel Name="stackPassword" Grid.Row="1">
            <TextBlock Text="Welcome back!" FontWeight="Bold" FontSize="18" HorizontalAlignment="Center"/>
            <TextBlock TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center">
                To unlock the CA client please enter the password:
            </TextBlock>
            <GroupBox Margin="30 30 30 3" Header="Password">
                <PasswordBox Name="passUnlock" Margin="3" PasswordChanged="passBox_PasswordChanged"/>
            </GroupBox>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="30 3">
                <Button Content="Unlock" Height="30" Width="150" Margin="3" IsDefault="True" Click="buttonUnlock_Click" Foreground="Green" FontWeight="Bold" IsEnabled="{Binding ElementName=w1, Path=UnlockEnabled}"/>
                <Button Content="Exit" Height="30" Width="100" Margin="3" Click="Exit_Click" Foreground="Red"/>
            </StackPanel>
        </StackPanel>

        <StackPanel Orientation="Vertical" VerticalAlignment="Center" Name="stackFirstRun" Visibility="Collapsed"  Grid.Row="1">
            <TextBlock Text="Welcome!" FontWeight="Bold" FontSize="18" HorizontalAlignment="Center"/>
            <TextBlock TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center">
                It appears it is the first time you're running the CA application. <LineBreak/>
                Before we start, we need to generate a 4096-byte RSA keypair and the associated certificate to use in the CA.<LineBreak/>
                If you want to do this now, enter a password to protect the private key in the box below and then click "Generate key"
            </TextBlock>

            <GroupBox Header="Password" Margin="3">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>

                    <TextBlock Text="Password" Margin="3"/>
                    <PasswordBox Margin="3" Grid.Column="1" Name="passBox" PasswordChanged="passBox_PasswordChanged"/>
                    <TextBlock Text="Repeat Password" Margin="3" Grid.Row="1"/>
                    <PasswordBox Margin="3" Grid.Column="1" Grid.Row="1" Name="passBoxRepeat" PasswordChanged="passBox_PasswordChanged"/>

                    <TextBlock Text="Notice: Remember this password! You will be asked for this password every time you start the CA to unlock the CA certificate." Foreground="Red" TextWrapping="Wrap" Grid.Row="2" Grid.ColumnSpan="2" Margin="3" TextAlignment="Center"/>
                </Grid>

            </GroupBox>

            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <Button Content="Generate Key!" Height="40" Width="150" Margin="4" Foreground="Green" FontWeight="Bold" FontSize="16" Click="GenerateKey_Click" IsEnabled="{Binding ElementName=w1, Path=PasswordsOk}" IsDefault="True"/>
                <Button Content="Exit" Height="40" Width="100" Foreground="Red" FontSize="16" Click="Exit_Click"/>
            </StackPanel>
        </StackPanel>

        <StackPanel Orientation="Vertical" VerticalAlignment="Center" Name="stackGenerating" Visibility="Collapsed" Grid.Row="1">
            <TextBlock HorizontalAlignment="Center" Text="Genrating keypair..." Margin="3" FontWeight="Bold" FontSize="18"/>
            <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Margin="3">
                Please wait, I'm generating the CA Keys and certificate <LineBreak/>
                This operation could take a while, depending on your CPU...
            </TextBlock>

            <ProgressBar IsIndeterminate="True" Width="Auto" Height="25" HorizontalAlignment="Stretch" Margin="30 10"></ProgressBar>
        </StackPanel>
    </Grid>
</Window>
